package com.me.libgdx_test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class ClassObjectGodDungeon extends AbstractClassObjectDungeon{
	
	private ClassDungeonGod god_info;
	private String altar_new_image, altar_used_image;
	boolean worshipping;
	boolean[] ritual_performed;
	HashMap<String,Integer[]> actions;
	HashMap<String,Integer> god_id;
	ClassObjectGodDungeon(ClassDungeonGod god_info, HashMap<String,Integer> god_id){
		this.god_info = god_info;
		this.god_id = god_id;
		altar_new_image = "loc_altar.png";
		altar_used_image = "loc_altarworship.png";
		worshipping = false;
		ritual_performed = new boolean[this.god_info.ritual_description.length];
		actions = new HashMap<String,Integer[]>();
		init_god_actions();
	}
	public String get_altar_image(){
		if(worshipping){
			return altar_used_image;
		}
		return altar_new_image;
	}
	public ClassDungeonGod get_god_info(){
		return god_info;
	}
	public void accept_god(ClassCharacterPlayer player, ClassPlaceObjects objects){
		if(god_info.Name.contains("Grog the Unholy")){
			player.get_class_mods().playerAttackMod.attack_mods.add("-15%_undead");
			player.get_class_mods().playerAttackMod.attack_mods.add("+25%_living");
		}
		if(god_info.Name.contains("Vark the Destroyer")){
			player.get_class_mods().playerAttackMod.attack_mods.add("10%_hp_kill");
		}
		if(god_info.Name.contains("Charn the Goddess")){
			player.get_class_mods().playerSpellMod.spell_cast_modifiers.add("+1_hp_endwall");
		}
		if(god_info.Name.contains("Phebos the Lover")){
			player.get_class_mods().playerSpellMod.spell_strength += .2f;
			for(ClassCharacterEnemy enemy:objects.get_enemies()){
				enemy.attack *= 1.1;
			}
		}
		if(god_info.Name.contains("Wix the Leech")){
			player.get_class_mods().playerPickupMod.blood_bonus.add("heal_5%");
			player.set_attack_mod("First Strike", true);
			player.set_player_variable("max_health", 1);
			player.set_player_variable("current_health", 1);
		}
		if(god_info.Name.contains("Angor the Eternal")){
			player.get_class_mods().playerAttackMod.attack_mods.add("+1_atk_death");
			player.get_class_mods().playerAttackMod.attack_mods.add("-50%_mana_death");
		}
		if(god_info.Name.contains("Mant the King")){
			player.get_class_mods().playerAttackMod.attack_mods.add("+25%_undead");
			player.get_class_mods().playerAttackMod.attack_mods.add("-15%_living");
		}
		if(god_info.Name.contains("Shuth the Warrior")){
			player.perm_attack_bonus += .5;
			player.set_player_variable("max_mana",1);
			player.set_player_variable("current_mana",1);
		}
		if(god_info.Name.contains("Quarzi the Chemist")){
			player.set_player_variable_float("health_potion_effectiveness", player.get_player_variable_float("health_potion_effectiveness") + .1f);
			player.set_player_variable_float("mana_potion_effectiveness", player.get_player_variable_float("mana_potion_effectiveness") + .1f);
		}
		if(god_info.Name.contains("Dun the Rock")){
			player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + 0.025f);
			player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + 0.025f);
		}
		if(god_info.Name.contains("Jesper the Poet")){
			player.get_class_mods().playerShroudMod.restore_health += 1;
			player.get_class_mods().playerShroudMod.restore_mana += 1;
			player.get_class_mods().playerSpellMod.spell_cast_modifiers.add("benefit_spells_poison");
		}
		if(god_info.Name.contains("Tyn the Cheat")){
			player.get_class_mods().playerSpellMod.spell_destruction_bonus += .5f;
			player.set_player_variable_float("mag_atk", player.get_player_variable_float("mag_atk") - .25f);
		}
		if(god_info.Name.contains("Nergal the Mage")){
			player.get_class_mods().playerSpellMod.spell_destruction_bonus = 0;
			player.set_player_variable_float("current_mana", player.get_player_variable("max_mana"));
		}
		if(god_info.Name.contains("Xysa the Witch")){
			player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") - .05f);
			player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + .1f);
		}
		if(god_info.Name.contains("Yin the Thug")){
			player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + .1f);
			player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") - .05f);
		}
	}
	public boolean check_piety(ClassCharacterPlayer player, int level){
		if(player.get_player_variable("piety") >= god_info.ritual_levels[0] * 10 && god_info.ritual_levels[level] != -1){
			player.set_player_variable("piety", player.get_player_variable("piety") - god_info.ritual_levels[level] * 10);
			//This means that the ritual has already been used and shouldnt be used again
			god_info.ritual_levels[level] = -1;
			return true;
		}
		return false;
		
	}
	public void perform_ritual(ClassCharacterPlayer player, int level){
		if(god_info.Name.contains("Grog the Unholy")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+45%_living");
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+85%_living");
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+160%_living");
					}
					break;
			}
		}
		if(god_info.Name.contains("Vark the Destroyer")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("40%_hp_kill");
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+2_hp_kill");
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+5_hp_kill");
					}
					break;
			}
		}
		if(god_info.Name.contains("Charn the Goddess")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+2_hp_endwall");
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+3_hp_endwall");
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+5_hp_endwall");
					}
					break;
			}
		}
		if(god_info.Name.contains("Phebos the Lover")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable("max_mana", player.get_player_variable("max_mana") + 15);
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("40%_dbl_dodge_status");
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.set_attack_mod("First Strike", true);
					}
					break;
			}
		}
		if(god_info.Name.contains("Wix the Leech")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable_float("double_hit", player.get_player_variable_float("double_hit") + .1f);
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.set_player_variable_float("life_steal", player.get_player_variable_float("life_steal") + .15f);
						player.set_player_variable("attack", player.get_player_variable("attack") + 5);
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerPickupMod.blood_bonus.add("heal_50%");
						player.set_player_variable("attack", player.get_player_variable("attack") + 10);
					}
					break;
			}
		}
		if(god_info.Name.contains("Angor the Eternal")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+3_atk_death");
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+5_atk_death");
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerShroudMod.enemy_visibility = "+5_health";
					}
					break;
			}
		}
		if(god_info.Name.contains("Mant the King")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+45%_undead");
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+85%_undead");
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerAttackMod.attack_mods.add("+160%_undead");
					}
					break;
			}
		}
		if(god_info.Name.contains("Shuth the Warrior")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.perm_attack_bonus += .75;
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.perm_attack_bonus += 1.5;
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.perm_attack_bonus += 3;
					}
					break;
			}
		}
		if(god_info.Name.contains("Quarzi the Chemist")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable("max_mana", player.get_player_variable("max_mana") + 5);
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.set_player_variable("max_health", player.get_player_variable("max_health") + 25);
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.set_player_variable_float("health_potion_effectiveness", 1);
						player.set_player_variable_float("mana_potion_effectiveness", 1);
					}
					break;
			}
		}
		if(god_info.Name.contains("Dun the Rock")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + .05f);
						player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + .05f);
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + .1f);
						player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + .1f);
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + .15f);
						player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + .15f);
					}
					break;
			}
		}
		if(god_info.Name.contains("Jesper the Poet")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerShroudMod.restore_health += 2;
						player.get_class_mods().playerShroudMod.restore_mana += 2;
						player.get_class_mods().playerShroudMod.cure_disease += .05;
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerShroudMod.restore_health += 3;
						player.get_class_mods().playerShroudMod.restore_mana += 3;
						player.get_class_mods().playerShroudMod.cure_disease += .15;
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerShroudMod.restore_health += 5;
						player.get_class_mods().playerShroudMod.restore_mana += 5;
						player.get_class_mods().playerShroudMod.cure_disease += .30;
					}
					break;
			}
		}
		if(god_info.Name.contains("Tyn the Cheat")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.get_class_mods().playerSpellMod.spell_destruction_bonus += .75;
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.get_class_mods().playerSpellMod.spell_destruction_bonus += 1.25;
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.get_class_mods().playerSpellMod.spell_destruction_bonus += 2.5;
					}
					break;
			}
		}
		if(god_info.Name.contains("Nergal the Mage")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable("max_mana", player.get_player_variable("max_mana")+5);
						player.get_class_mods().playerSpellMod.spell_strength += .05;
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.set_player_variable("max_mana", player.get_player_variable("max_mana")+20);
						player.get_class_mods().playerSpellMod.spell_strength += .20;
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.set_player_variable("max_mana", player.get_player_variable("max_mana")+35);
						player.get_class_mods().playerSpellMod.spell_strength += .35;
					}
					break;
			}
		}
		if(god_info.Name.contains("Xysa the Witch")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable_float("phys_def", player.get_player_variable_float("phys_def") + .15f);
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.set_immune_mod("Weakness", true);
						player.set_immune_mod("Poison", true);
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.set_attack_mod("Poison", true);
					}
					break;
			}	
		}
		if(god_info.Name.contains("Yin the Thug")){
			switch(level){
				case 0:
					if(check_piety(player,level)){
						player.set_player_variable_float("mag_def", player.get_player_variable_float("mag_def") + .15f);
					}
					break;
				case 1:
					if(check_piety(player,level)){
						player.set_immune_mod("Banish", true);
						player.set_immune_mod("Static", true);
					}
					break;
				case 2:
					if(check_piety(player,level)){
						player.set_attack_mod("First Strike", true);
					}
					break;
			}	
		}
	}
	
	public void init_god_actions(){
		actions.put("kill_undead", new Integer[]{-10,0,0,0,0,0,5,0,0,0,0,0,0,0,0});
		actions.put("kill_living", new Integer[]{5,0,0,0,0,0,-10,0,0,0,0,0,0,0,0});
		actions.put("got_hit", new Integer[]{0,0,0,-10,0,0,0,0,0,2,0,0,0,0,0,0});
		actions.put("did_hit", new Integer[]{0,0,0,0,2,0,0,2,0,0,0,0,0,0,0});
		actions.put("hit_twice", new Integer[]{0,0,0,0,0,0,0,0,-10,0,0,0,0,0,0});
		actions.put("did_killed", new Integer[]{0,5,0,0,0,-6,0,0,0,0,0,0,0,0,0});
		actions.put("got_killed", new Integer[]{0,0,0,0,0,10,0,0,0,-25,0,0,0,0,0});
		actions.put("benefits", new Integer[]{0,0,0,0,0,0,0,0,0,0,-2,0,0,0,0});
		actions.put("ailments", new Integer[]{0,0,0,0,0,0,0,0,0,0,3,0,0,0,0});
		actions.put("made_walls", new Integer[]{0,0,5,0,0,0,0,0,0,0,0,0,0,0,0});
		actions.put("destroyed_walls", new Integer[]{0,0,-10,0,0,0,0,0,0,0,0,0,0,0,0});
		actions.put("used_magic", new Integer[]{0,0,0,2,0,0,0,-10,0,0,0,-4,2,0,0});
		actions.put("glyph_destruction", new Integer[]{0,0,0,0,0,0,0,0,0,0,0,20,-25,0,0});
		actions.put("bought_goods", new Integer[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});
		actions.put("used_items", new Integer[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});
		actions.put("dodged", new Integer[]{0,-10,0,0,0,0,0,0,0,0,0,0,0,0,0});
		actions.put("blood_pools", new Integer[]{0,0,0,0,5,0,0,0,0,0,0,0,0,0,0});
		actions.put("potions", new Integer[]{0,0,0,0,-10,0,0,0,5,0,0,0,0,0,0});
		actions.put("magic_enemy", new Integer[]{0,0,0,0,0,0,0,0,0,0,0,0,0,-10,7});
		actions.put("phys_enemy", new Integer[]{0,0,0,0,0,0,0,0,0,0,0,0,0,7,-10});
	}
	
	public void action_performed(ClassCharacterPlayer player, String action){
		if(actions.containsKey(action)){
			player.set_player_variable("piety", player.get_player_variable("piety") + actions.get(action)[god_id.get(god_info.Name)]);
		}
	}
	
	/*class god_action_object{
		String action;
		ArrayList<Integer> opinion;
		god_action_object(String action, Integer[] opinion){
			this.action = action;
			this.opinion = new ArrayList<Integer>(Arrays.asList(opinion));
		}
	}*/
}
